// directory.js
// var address = require('../../../utils/city.js')
const app = getApp()
var animation
var alldeta
Page({

  data: {
    menuType: 0,
    begin: null,
    status: 1,
    end: null,
    isVisible: false,
    animationData: {},
    animationAddressMenu: {},
    addressMenuIsShow: false,
    value: [0, 0, 0],
    areaInfo:"",
    myaddress:""
  },

  
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let name_ = wx.getStorageSync('name_');
    let phone_ = wx.getStorageSync('phone_');
    var that = this;
    var prove = options.prove;
    var city = options.city;
    var dist = options.dist;
    alldeta = prove + city + dist;

    if (alldeta){
      alldeta = alldeta;
    }else{
      alldeta = "";
    }

    this.setData({
      name_: name_,
      phone_: phone_,
      myaddress: alldeta,
    })
    // console.log(prove); console.log(city); console.log(dist);
    
  },


  name_inp:function(e){
    let name_ = e.detail.value;
    wx.setStorageSync('name_', name_);
  },
  phone_inp: function (e) {
    let phone_ = e.detail.value;
    wx.setStorageSync('phone_', phone_);
  },
  clear_:function(){
    wx.clearStorageSync();
  },
  // 显示
  showMenuTap: function (e) {
    console.log('selectState')
    //获取点击菜单的类型 1点击状态 2点击时间 
    var menuType = e.currentTarget.dataset.type
    // 如果当前已经显示，再次点击时隐藏
    if (this.data.isVisible == true) {
      this.startAnimation(false, -200)
      return
    }
    this.setData({
      menuType: menuType
    })
    this.startAnimation(true, 0)
  },
  hideMenuTap: function (e) {
    this.startAnimation(false, -200)
  },
  // 执行动画
  startAnimation: function (isShow, offset) {
    var that = this
    var offsetTem
    if (offset == 0) {
      offsetTem = offset
    } else {
      offsetTem = offset + 'rpx'
    }
    this.animation.translateY(offset).step()
    this.setData({
      animationData: this.animation.export(),
      isVisible: isShow
    })
    console.log(that.data)
  },
  // 选择状态按钮
  selectState: function (e) {
    console.log('selectState1')
    this.startAnimation(false, -200)
    var status = e.currentTarget.dataset.status
    this.setData({
      status: status
    })
    console.log(this.data)
  },
  // 日志选择
  bindDateChange: function (e) {
    console.log(e)
    if (e.currentTarget.dataset.type == 1) {
      this.setData({
        begin: e.detail.value
      })
    } else if (e.currentTarget.dataset.type == 2) {
      this.setData({
        end: e.detail.value
      })
    }
  },
  sureDateTap: function () {
    this.data.pageNo = 1
    this.startAnimation(false, -200)
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  // 点击所在地区弹出选择框
  selectDistrict: function (e) {
    var that = this
    // if (that.data.addressMenuIsShow) {
    //   return
    // }
    // that.startAddressAnimation(true)
    wx.navigateTo({
      url: "/pages/yiguo/citys/citys"
    }) 
  },

 
//立即添加
  formSubmit: function (e) {
    var address = e.detail.value.address;
    var name = e.detail.value.name;
    var phone = e.detail.value.phone;
    var uid = app.whereId.uid;
    var sheng = e.detail.value.sheng;
    wx.request({
      url: 'https://www.cakeyouxuan.com/small/my/add_add',
      data: {
        id: uid,
        name: name,
        phone: phone,
        address: address,
        sheng: sheng,
      },
      method: "POST",
      header: {
        "Content-Type": "application/x-www-form-urlencoded"  //post
      },
      success: function (res) {
        if (res.data.msg == 'T') {
          wx.showToast({
            title: '添加成功',
            icon: 'success',
            duration: 1000,
            success: function () {
              setTimeout(function () {
                //要延时执行的代码
                wx.navigateTo ({
                  url: "/pages/yiguo/address/address",
                })
              }, 1000) //延迟时间
            }
          })

        }
      },
    })
  },
  // validatemobile: function (mobile) {
  //   if (mobile.length == 0) {
  //     wx.showToast({
  //       title: '请输入手机号！',
  //       icon: 'success',
  //       duration: 1500
  //     })
  //     return false;
  //   }
  //   if (mobile.length != 11) {
  //     wx.showToast({
  //       title: '手机号长度有误！',
  //       icon: 'success',
  //       duration: 1500
  //     })
  //     return false;
  //   }
  //   var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/;
  //   if (!myreg.test(mobile)) {
  //     wx.showToast({
  //       title: '手机号有误！',
  //       icon: 'success',
  //       duration: 1500
  //     })
  //     return false;
  //   }
  //   return true;
  // }

})

